package org.jsola.contract.helper;

import org.jsola.common.SafeKit;
import org.jsola.contract.constant.AccountType;
import org.jsola.contract.dto.SealPositionAddDTO;
import org.jsola.contract.dto.SealPositionUpdateDTO;
import org.jsola.contract.entity.SealPositionDO;
import org.jsola.contract.query.SealPositionQuery;
import org.jsola.contract.service.ISealPositionService;
import org.jsola.contract.vo.SealPositionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.contract.core.AbstractTest.SITE_ID;



/**
 * 合同默认签章位置
 *
 * @author JanusMix
 */
@Component
public class SealPositionTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISealPositionService sealPositionService;

    /**
     * 生成add测试数据
     * @return SealPositionAddDTO
     */
    public SealPositionAddDTO getSealPositionAddDTO(){
        SealPositionAddDTO sealPositionAddDTO = new SealPositionAddDTO();
        sealPositionAddDTO.setTemplateId(SafeKit.getLong(getRandomValue("bigint",11)));
        sealPositionAddDTO.setAppendixId(SafeKit.getLong(getRandomValue("bigint",11)));
        sealPositionAddDTO.setAccountType(AccountType.PERSON.getValue());
        sealPositionAddDTO.setType(SafeKit.getInteger(getRandomValue("int",11)));
        sealPositionAddDTO.setSealPage(SafeKit.getInteger(getRandomValue("int",11)));
        sealPositionAddDTO.setSealPositionX(getRandomValue("varchar",32));
        sealPositionAddDTO.setSealPositionY(getRandomValue("varchar",32));
        return sealPositionAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SealPositionUpdateDTO
     */
    public SealPositionUpdateDTO getSealPositionUpdateDTO(SealPositionVO sealPositionVO){
        return sealPositionService.selectDOById(sealPositionVO.getId(), SITE_ID).to(SealPositionUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SealPositionQuery
     */
    public SealPositionQuery getSealPositionQuery() {
        SealPositionQuery sealPositionQuery = new SealPositionQuery();
        List<SealPositionDO> sealPositionDOList = sealPositionService.list(new SealPositionDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(sealPositionDOList)) {
            SealPositionDO sealPositionDO = sealPositionDOList.get(0);
            sealPositionQuery = sealPositionDO.to(SealPositionQuery.class);
        }
        return sealPositionQuery;
    }

    /**
     * 保存示例
     * @return SealPositionVO
     */
    public SealPositionVO saveSealPositionExample(){
        SealPositionAddDTO addDTO = this.getSealPositionAddDTO();
        SealPositionVO sealPositionVO = sealPositionService.save(addDTO,buildTokenUser());
        return sealPositionVO;
    }


}

